package com.spider.admin.store.primary.mapper;

import com.spider.admin.store.primary.model.AgentOption;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AgentOptionsMapper {
    @Select({"<script>",
            "select * from t_agent_options where 1=1",
            "<if test='section != null'> AND section = #{section}</if>",
            "<if test='optionItem != null'> AND option_item = #{optionItem}</if>",
            " order by section,option_item",
            " limit #{pageSize} offset #{startRow}",
            "</script>"})
    @Results(value = {
            @Result(column = "pid", property = "pid"),
            @Result(column = "section", property = "section"),
            @Result(column = "option_item", property = "optionItem"),
            @Result(column = "option_desc", property = "optionDesc")
    })
    List<AgentOption> queryAgentOptions(int startRow,int pageSize,String section, String optionItem);

    @Insert("insert into t_agent_options(pid,section,option_item,option_desc) values(#{pid},#{section},#{optionItem},#{optionDesc})")
    int saveAgentOption(AgentOption agentOption);

    @Update({"<script>",
            "update t_agent_options set option_item=#{agentOption.optionItem},section=#{agentOption.section}",
            "<if test='agentOption.optionDesc != null'> ,option_desc = #{agentOption.optionDesc}</if>",
            "where pid=#{pid}",
            "</script>"})
    int updateAgentOption(String pid, AgentOption agentOption);

    @Delete("delete from t_agent_options where pid=#{pid}")
    int deleteAgentOption(String pid);

    @Select({"<script>",
            "select count(0) from t_agent_options where 1=1",
            "<if test='section != null'> AND section = #{section}</if>",
            "<if test='optionItem != null'> AND option_item = #{optionItem}</if>",
            "</script>"})
    Long queryAgentOptionsNum(String section, String optionItem);
}
